<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>天气案例</title>
  </head>

  <body>
    <div id="app">
      <h1>今天的天气很{{info}}</h1>
      <button @click="changeClimate">切换天气</button>
    </div>
  </body>
  <script src="../js/vue.js"></script>
  <script>
    const vm = new Vue({
      el: "#app",
      data: {
        isShow: true
      },
      methods: {
        changeClimate() {
          return this.isShow = !this.isShow
        }
      },
      computed: {
        info() {
          return this.isShow ? '炎热' : '凉爽'
        }
      },
      // 监视的第一种写法:new Vue时传入watch配置
      /* watch: {
        isShow: {
          immediate: true,//在加载的时候先执行一次
          deep:true,//深度监视
          handler(newValue, oldValue) {
            console.log("执行了watch");
            console.log(newValue, oldValue);
          }
        }
      } */
      /*  watch: {
         isShow(newValue, oldValue) {
           console.log("执行了watch");
           console.log(newValue, oldValue);
         }
       } */
    })
    // 监视的第二种写法：通过vm.$watch监视
    // vm.$watch('isShow', {
    //   immediate: true,
    //   handler(newValue, oldValue) {
    //     console.log("执行了监视", newValue, oldValue);
    //   }
    // })
    vm.$watch('isShow', function (newValue, oldValue) {
      console.log("执行了监视", newValue, oldValue);
    })
  </script>


</html>